<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>添加球队</title>
		<script type="text/javascript" src="../../js/jquery-1.11.1.js"></script>
		<script type="text/javascript" src="../../js/bootstrap.js"></script>
		<script src="../../js/global.js"></script>
		<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css"></link>
		<link rel="stylesheet" type="text/css" href="../../css/style.css"></link>
		<style>
			label span{color: #ff0000; padding-right: 5px;}
		</style>
	</head>

	<body>
		<h2>添加赛程</h2>
		<form id="myForm" class="form-horizontal" method="post" action="/team">	
			<div class="form-group">
				<label class="col-sm-1 control-label">比赛时间</label>
				<div class="col-sm-2">
					<input name="gameDate" class="form-control" type="date"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">主队</label>
				<div class="col-sm-2">
					<select name="homeTeamId" class="form-control">
         				<option value="-1">请选择主队</option>
         				<!--<option value="0">延期</option>
         				<option value="1">正常</option>-->
			      	</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><span>*</span>主队得分</label>
				<div class="col-sm-9">
					<input required="required" name="homeTeamScore" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">客队</label>
				<div class="col-sm-2">
					<select name="visitingTeamId" class="form-control">
         				<option value="-1">请选择客队</option>
         				<!--<option value="0">延期</option>
         				<option value="1">正常</option>-->
			      	</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><span>*</span>客队得分</label>
				<div class="col-sm-9">
					<input required="required" name="visitingTeamScore" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">比赛类型</label>
				<div class="col-sm-2">
					<select name="typeId" class="form-control">
         				<option value="-1">请选择比赛类型</option>
         				<option value="1">季前赛</option>
         				<option value="2">常规赛</option>
         				<option value="3">季后赛</option>
         				<option value="4">总决赛</option>
         				<option value="5">全明星赛</option>
			      	</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">状态</label>
				<div class="col-sm-2">
					<select name="status" class="form-control">
         				<option value="-1">请选择状态</option>
         				<option value="1">正常</option>
         				<option value="2">延期</option>
			      	</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"></label>
				<div class="col-sm-9">
					<button id="btnAdd" type="button" class="btn btn-sm btn-info">提&nbsp;交</button>
					<button type="reset"  class="btn btn-sm btn-warning">重&nbsp;置</button>
				</div>
			</div>
		</form>		
	</body>
</html>
<script>
	$(function () {
		// 查询球队信息
		$.ajax({
			type: "GET",
			url: myurl + "/team?forwardUrl=" + forwardUrl,
			dataType:"json",
			xhrFields: {
			    withCredentials: true
			},
			crossDomain: true,
			data: null,
			success: function(vo){
				if(vo.code==200) {
					$.each(vo.pageInfo.list, function(){
						$("select[name='homeTeamId']").append("<option value='"+ this.teamId +"'>"+ this.chineseName +"</option>")
					})
					$.each(vo.pageInfo.list, function(){
						$("select[name='visitingTeamId']").append("<option value='"+ this.teamId +"'>"+ this.chineseName +"</option>")
					})
				}else{
					alert(vo.msg);
				}
			}
		})
		
		//提交按钮的单击事件
		$("#btnAdd").click(function () {
			$.ajax({
				type: "POST",
				url: myurl + "/game?forwardUrl=" + forwardUrl,
				data: $("#myForm").serialize(),
				dataType:"json",
				success: function(vo){
					if(vo.code==200) {
						window.location.href = "list.html";
					}else{
						alert("添加失败！"+vo.msg);
					}
				}
			});
		});
	});
</script>